home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Graphics 2D / Icon Display / IconDisplay.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.6 KB  |  183 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        IconDisplay.c
  3.  
  4.     Contains:    Demonstartion of manual drawing from icon resources to an offscreen buffer,
  5.                 then onscreen blitting. 
  6.  
  7.     Written by:     
  8.  
  9.     Copyright:    Copyright © 1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 7/9/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24. #include <MacTypes.h>
  25. #include <Quickdraw.h>
  26. #include <Fonts.h>
  27. #include <Windows.h>
  28. #include <Dialogs.h>
  29. #include <Menus.h>
  30. #include <TextEdit.h>
  31. #include <Menus.h>
  32. #include <Events.h>
  33. #include "IconMenus.h"
  34. #include "IconWindow.h"
  35.  
  36. extern    WindowPtr    bullseyeWindow;
  37. extern    Rect        dragRect;
  38. extern  Rect        PlotRect;
  39.  
  40. void InitMacintosh();
  41. void HandleMouseDown(EventRecord    *theEvent);
  42. void HandleEvent();
  43. /****
  44.  * InitMacintosh()
  45.  *
  46.  * Initialize all the managers & memory
  47.  *
  48.  ****/
  49.  
  50. void InitMacintosh()
  51.  
  52. {
  53.     MaxApplZone();
  54.     
  55.     InitGraf(&qd.thePort);
  56.     InitFonts();
  57.     FlushEvents(everyEvent, 0);
  58.     InitWindows();
  59.     InitMenus();
  60.     TEInit();
  61.     InitDialogs(0L);
  62.     InitCursor();
  63.  
  64. }
  65. /* end InitMacintosh */
  66.  
  67.  
  68. /****
  69.  * HandleMouseDown (theEvent)
  70.  *
  71.  *    Take care of mouseDown events.
  72.  *
  73.  ****/
  74.  
  75. void HandleMouseDown(EventRecord    *theEvent)
  76. {
  77.     WindowPtr    theWindow;
  78.     int            windowCode = FindWindow (theEvent->where, &theWindow);
  79.     
  80.     switch (windowCode)
  81.       {
  82.       case inSysWindow: 
  83.         SystemClick (theEvent, theWindow);
  84.         break;
  85.         
  86.       case inMenuBar:
  87.           AdjustMenus();
  88.         HandleMenu(MenuSelect(theEvent->where));
  89.         break;
  90.         
  91.       case inDrag:
  92.           if (theWindow == bullseyeWindow)
  93.             DragWindow(bullseyeWindow, theEvent->where, &dragRect);
  94.             FindNewDevice(bullseyeWindow);  /* see if the device has changed and inval small icon if so*/
  95.             break;
  96.             
  97.       case inContent:
  98.           if (theWindow == bullseyeWindow)
  99.             {
  100.             if (theWindow != FrontWindow())
  101.               SelectWindow(bullseyeWindow);
  102.             else
  103.               InvalRect(&bullseyeWindow->portRect);
  104.             }
  105.           break;
  106.           
  107.       case inGoAway:
  108.           if (theWindow == bullseyeWindow && 
  109.               TrackGoAway(bullseyeWindow, theEvent->where))
  110.           HideWindow(bullseyeWindow);
  111.             break;
  112.       }
  113. }
  114. /* end HandleMouseDown */
  115.  
  116.  
  117. /****
  118.  * HandleEvent()
  119.  *
  120.  *        The main event dispatcher. This routine should be called
  121.  *        repeatedly (it  handles only one event).
  122.  *
  123.  *****/
  124.  
  125. void HandleEvent()
  126.  
  127. {
  128.     int            ok;
  129.     EventRecord    theEvent;
  130.  
  131.     HiliteMenu(0);
  132.     SystemTask ();        /* Handle desk accessories */
  133.     
  134.     ok = GetNextEvent (everyEvent, &theEvent);
  135.     if (ok)
  136.       switch (theEvent.what)
  137.         {
  138.         case mouseDown:
  139.             HandleMouseDown(&theEvent);
  140.             break;
  141.             
  142.         case keyDown: 
  143.         case autoKey:
  144.             if ((theEvent.modifiers & cmdKey) != 0)
  145.               {
  146.               AdjustMenus();
  147.               HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
  148.               }
  149.             break;
  150.             
  151.         case updateEvt:
  152.             BeginUpdate(bullseyeWindow);
  153.             DrawBullseye(((WindowPeek) bullseyeWindow)->hilited);
  154.             EndUpdate(bullseyeWindow);
  155.             break;
  156.             
  157.         case activateEvt:
  158.             InvalRect(&bullseyeWindow->portRect);
  159.             break;
  160.         }
  161. }
  162. /* end HandleEvent */
  163.  
  164.  
  165. /*****
  166.  * main()
  167.  *
  168.  *    This is where everything happens
  169.  *
  170.  *****/
  171.  
  172.  
  173. void main()
  174.  
  175. {
  176.     InitMacintosh();
  177.     SetUpMenus();
  178.     SetUpWindow();
  179.     
  180.     for (;;)
  181.         HandleEvent();
  182. }
  183. /* end main */